home *** CD-ROM | disk | FTP | other *** search
- Public Class AnchorForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents Button2 As System.Windows.Forms.Button
- Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
- Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
- Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
- Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
- Friend WithEvents Button1 As System.Windows.Forms.Button
- Friend WithEvents Button3 As System.Windows.Forms.Button
- Friend WithEvents Label1 As System.Windows.Forms.Label
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.Button2 = New System.Windows.Forms.Button()
- Me.Button3 = New System.Windows.Forms.Button()
- Me.TextBox1 = New System.Windows.Forms.TextBox()
- Me.CheckBox1 = New System.Windows.Forms.CheckBox()
- Me.CheckBox2 = New System.Windows.Forms.CheckBox()
- Me.TextBox2 = New System.Windows.Forms.TextBox()
- Me.Button1 = New System.Windows.Forms.Button()
- Me.Label1 = New System.Windows.Forms.Label()
- Me.SuspendLayout()
- '
- 'Button2
- '
- Me.Button2.Location = New System.Drawing.Point(384, 128)
- Me.Button2.Name = "Button2"
- Me.Button2.Size = New System.Drawing.Size(80, 32)
- Me.Button2.TabIndex = 1
- Me.Button2.Text = "Cancel"
- '
- 'Button3
- '
- Me.Button3.Location = New System.Drawing.Point(384, 168)
- Me.Button3.Name = "Button3"
- Me.Button3.Size = New System.Drawing.Size(80, 32)
- Me.Button3.TabIndex = 0
- Me.Button3.Text = "OK"
- '
- 'TextBox1
- '
- Me.TextBox1.Location = New System.Drawing.Point(8, 24)
- Me.TextBox1.Name = "TextBox1"
- Me.TextBox1.Size = New System.Drawing.Size(352, 20)
- Me.TextBox1.TabIndex = 3
- Me.TextBox1.Text = ""
- '
- 'CheckBox1
- '
- Me.CheckBox1.Location = New System.Drawing.Point(8, 64)
- Me.CheckBox1.Name = "CheckBox1"
- Me.CheckBox1.Size = New System.Drawing.Size(104, 16)
- Me.CheckBox1.TabIndex = 5
- Me.CheckBox1.Text = "Anchor Controls"
- '
- 'CheckBox2
- '
- Me.CheckBox2.Location = New System.Drawing.Point(128, 64)
- Me.CheckBox2.Name = "CheckBox2"
- Me.CheckBox2.Size = New System.Drawing.Size(216, 16)
- Me.CheckBox2.TabIndex = 6
- Me.CheckBox2.Text = "Enforce Min/Max Size"
- '
- 'TextBox2
- '
- Me.TextBox2.Location = New System.Drawing.Point(8, 96)
- Me.TextBox2.Multiline = True
- Me.TextBox2.Name = "TextBox2"
- Me.TextBox2.Size = New System.Drawing.Size(352, 104)
- Me.TextBox2.TabIndex = 4
- Me.TextBox2.Text = "Click on the checkbox to anchor controls, then resize and maximize this form"
- '
- 'Button1
- '
- Me.Button1.Location = New System.Drawing.Point(384, 16)
- Me.Button1.Name = "Button1"
- Me.Button1.Size = New System.Drawing.Size(80, 32)
- Me.Button1.TabIndex = 2
- Me.Button1.Text = "Save"
- '
- 'Label1
- '
- Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
- Me.Label1.Dock = System.Windows.Forms.DockStyle.Bottom
- Me.Label1.Location = New System.Drawing.Point(0, 213)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(472, 16)
- Me.Label1.TabIndex = 7
- Me.Label1.Text = "A docked Label control "
- Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
- '
- 'AnchorForm
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- Me.ClientSize = New System.Drawing.Size(472, 229)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.CheckBox2, Me.CheckBox1, Me.TextBox2, Me.TextBox1, Me.Button1, Me.Button2, Me.Button3})
- Me.Name = "AnchorForm"
- Me.Text = "Anchor and Dock Property"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
- If CheckBox1.Checked Then
- ' enforce anchoring for all controls
- TextBox1.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right
- TextBox2.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top Or AnchorStyles.Bottom
- Button1.Anchor = AnchorStyles.Top Or AnchorStyles.Right
- Button2.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
- Button3.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
- Else
- ' disable anchoring for all controls
- TextBox1.Anchor = AnchorStyles.Top Or AnchorStyles.Left
- TextBox2.Anchor = AnchorStyles.Top Or AnchorStyles.Left
- Button1.Anchor = AnchorStyles.Top Or AnchorStyles.Left
- Button2.Anchor = AnchorStyles.Top Or AnchorStyles.Left
- Button3.Anchor = AnchorStyles.Top Or AnchorStyles.Left
- End If
- End Sub
-
- Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
- If CheckBox1.Checked Then
- ' enforce min/max size for this form
- Me.MaximumSize = New System.Drawing.Size(700, 460)
- Me.MinimumSize = New System.Drawing.Size(300, 240)
- Else
- ' don't enforce min/max size
- Me.MaximumSize = Nothing
- Me.MinimumSize = Nothing
- End If
- End Sub
- End Class
-